﻿using HomeCloudStorageSystem.DataBase;
using HomeCloudStorageSystem.Models;

namespace HomeCloudStorageSystem.Services
{
    public class DiaryRepository : IDiaryRepository
    {
        private readonly AppDbContext _context;
        public DiaryRepository(AppDbContext context) {  _context = context; }
        public IEnumerable<Diary> GetDiarieByUserIds(int userId)
        {
            return _context.Diary.Where(n => n.UserId == userId).OrderByDescending(i => i.Id).ToList();
        }
        public Diary GetDiaryByIdUserId(int id)
        {
            return _context.Diary.Where(n => n.Id == id).FirstOrDefault();
        }
        public void AddDiary(Diary diary)
        {
            _context.Diary.Add(diary);
        }
        public void RemoveDiary(Diary diary)
        {
            _context.Diary.Remove(diary);
        }
        public bool Save()
        {
            return (_context.SaveChanges() > 0);
        }
    }
}
